package com.visionblue.business.ship.base

import android.app.ActivityManager
import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.app.hubert.guide.core.Builder
import com.visionblue.business.ship.R
import com.visionblue.business.ship.page.dialog.LoadingDialog
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel

/**
 * @author: xlh
 * @date: 2020-04-10 1:43 PM
 * @desc:
 */
abstract class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope() {

    protected val mDialog: LoadingDialog by lazy {
        LoadingDialog(this)
    }

    open val layoutId: Int = R.layout.activity_common

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(layoutId)
        initView(savedInstanceState)
        initData()
        Log.e("---->", getRunningActivityName())
    }

    protected open fun initData() {

    }

    protected open fun initView(savedInstanceState: Bundle?) {

    }

    override fun onDestroy() {
        super.onDestroy()
        cancel()
    }

    open fun getRunningActivityName(): String? {
        val activityManager =
            getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        return activityManager.getRunningTasks(1)[0].topActivity.className
    }
}